#ifndef __BASE_DRIVER_H
#define __BASE_DRIVER_H

#include <rclcpp/rclcpp.hpp> 
#include <boost/shared_ptr.hpp>

#include <geometry_msgs/msg/twist.hpp>
#include <tf2_ros/transform_broadcaster.h>
#include <nav_msgs/msg/odometry.hpp>
#include <sensor_msgs/msg/imu.hpp>
#include <std_msgs/msg/int16.hpp>
#include <std_msgs/msg/float32.hpp>
#include <std_msgs/msg/int32.hpp>
#include <std_msgs/msg/char.hpp>
#include <std_msgs/msg/u_int32.hpp>
#include <std_msgs/msg/u_int8_multi_array.hpp>
#include <std_msgs/msg/u_int8.hpp>
#include <std_msgs/msg/int8.hpp>
#include <std_msgs/msg/u_int16_multi_array.hpp>
#include <std_msgs/msg/string.hpp>


#include "dataframe.h"

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <ubt_interface/msg/battery_data.hpp>
#include "tcptalk.h"
#include "timer_ros.h"
#include "m_utility_fun.h"
#include "rclcpp/rclcpp.hpp"

class BaseDriver
{
private:
  BaseDriver();

public:
  static BaseDriver* Instance()
  {

    if (instance == NULL)
      instance = new BaseDriver();

    return instance;
  }

  static rclcpp::Node::SharedPtr node;
  static void set_static_node(rclcpp::Node::SharedPtr n)
  {
    node = n;
  }

  ~BaseDriver();
  void work_loop();
  void init_ros_topic();

  static void Get_PB_Status(BaseDriver* base);
  static void Get_Battery_Data(BaseDriver* base);  
  static void Get_Charge_Status(BaseDriver* base);
  static void Get_Btn_Data(BaseDriver* base);
  static void Send_Heart_Beat(BaseDriver* base);
  static void Read_Pb_Version(BaseDriver* base);
  static void Check_Limit_Power(BaseDriver* base);



  void Ubt_State_o_Obstacle_Alarm_Callback(const std_msgs::msg::String::SharedPtr alarm);
  void LedbarOrder_Callback(const std_msgs::msg::UInt8MultiArray::SharedPtr rdata);
  void Mb_Status_Callback(const std_msgs::msg::UInt32::SharedPtr status);
  void Base_Driver_Param_Get(void);
public:

//   ros::NodeHandle* getNodeHandle(){
  //   return &nh;
  // }
  
  rclcpp::Publisher<std_msgs::msg::String>::SharedPtr pb_version_pub;
  int g_Limit_Power;
  int g_Lower_Power;
  std_msgs::msg::String Power_state;
  unsigned char Obstacle_Alarm;
  rclcpp::Publisher<std_msgs::msg::String>::SharedPtr power_state_pub;

private:
  static BaseDriver* instance;

//   ros::NodeHandle nh;

  rclcpp::Publisher<std_msgs::msg::UInt32>::SharedPtr pb_status_pub;  
  rclcpp::Publisher<ubt_interface::msg::BatteryData>::SharedPtr battery_data_pub;  
  rclcpp::Publisher<std_msgs::msg::UInt8>::SharedPtr charge_status_pub;
  rclcpp::Publisher<std_msgs::msg::Int8>::SharedPtr lift_cmd_pub;
  rclcpp::Subscription<std_msgs::msg::String>::SharedPtr ubt_state_o_obstacle_alarm_sub;

  
  rclcpp::Subscription<std_msgs::msg::UInt8MultiArray>::SharedPtr ledbar_order_sub;  
  rclcpp::Subscription<std_msgs::msg::UInt32>::SharedPtr mb_status_sub;  

  uint32_t g_Mb_Status;

};

#endif


